function jianTuan(ev, ok) {
	if($("#createtuanform").valid() === true) {
		ev.stopPropagation();
		ok = (typeof ok != 'undefined') ? ok : false;
		if (ok) return true;
		$.blockUI({ message: $('#question_jiantuan'), css: { width: '400px',height:'100px',border:'10px solid #999999'} });
		return false;
	}
}
$(document).ready(function() {
	$('.price_input').blur(function() {
		if(!$.trim(this.value).length) {
			$(this).prop("value", 0);
		}
	});

        $('.input_control').click(function(){
		if($(this).prop("checked") == true) {
                	$("input[id='"+ $(this).prop('value')+"']").prop("disabled", false);
		} else {
                	$("input[id='"+ $(this).prop('value')+"']").prop("disabled", true);   
		}
        });

        $('#group_tiyan_y').click(function(){
                	$("input[id='tiyan_location']").prop("disabled", false);
                	$("#tiyan_time_from").datetimebox({"disabled":false});
                	$("#tiyan_time_to").datetimebox({"disabled":false});
        });

        $('#group_tiyan_n').click(function(){
                	$("input[id='tiyan_location']").prop("disabled", true);
                	$("#tiyan_time_from").datetimebox({"disabled":true});
                	$("#tiyan_time_to").datetimebox({"disabled":true});
        });

        $('#group_zhifu_a').click(function(){
                	$("input[id='tihuo_location']").prop("disabled", false);
                	$("input[id='taobao_link']").prop("disabled", true);
        });
        $('#group_zhifu_b').click(function(){
                	$("input[id='tihuo_location']").prop("disabled", true);
                	$("input[id='taobao_link']").prop("disabled", true);
        });
        $('#group_zhifu_c').click(function(){
                	$("input[id='tihuo_location']").prop("disabled", true);
                	$("input[id='taobao_link']").prop("disabled", false);
        });

	 $("#createtuanform").validate({
                rules: {
                        tuanname: {
                                required: true,
                                minlength:1,
                                maxlength:20
                        },
			personnum: {
				required: true,
				min:1,
				digits:true
			},
			wishprice: {
				required: true,
				min:0,
				number:true
			},
			quantity: {
				required: true,
				min:1,
				digits:true
			},
                        terms: "required"
                },
                messages: {
                        tuanname: {
                                required: "给你的团取个名字吧亲!",
                                minlength: jQuery.format("请输入最少 {0} 个字符"),
                                maxlength: jQuery.format("团名最多 {0} 个字符")
                        },
                        personnum: {
                                required: "请输入预期参团人数",
                                min: jQuery.format("预期参团人数最少为 {0} 人"),
                                digits: jQuery.format("请输入整数")
                        },
                        wishprice: {
                                required: "请输入预期价格",
                                min: jQuery.format("预期价格最少为 {0} 元"),
                                number: jQuery.format("请输入输入合法的数字")
                        },
                        quantity: {
                                required: "请输入您要购买的数量",
                                min: jQuery.format("预期购买数量最少为 {0} 件"),
                                digits: jQuery.format("请输入整数")
                        },
                        terms: " "
                },
                // the errorPlacement has to take the table layout into account
                errorPlacement: function(error, element) {
                        if ( element.is(":radio") )
                                error.appendTo( element.parent().next().next() );
                        else if ( element.is(":checkbox") )
                                error.appendTo ( element.next() );
                        else
                                error.appendTo( element.parent().next() );
                },
                // set this class to error-labels to indicate valid fields
                success: function(label) {
                        // set &nbsp; as text for IE
                        label.html("&nbsp;").addClass("checked");
                }
        });

	$('#createtuanform').bind('submit', jianTuan);
	$('#yes_jiantuan').click(function() {
                $('#createtuanform').trigger('submit', [true]);
                $.blockUI({ message: "<div style=\"margin-left:50px;flaot:left;margin-top:15px;font-size:14px;color:#999999;\">处理中...请不要关闭该页面！</div>" , css:{height:'50px',width:'400px',border:'10px solid #999999'}});
        });

        $('#no_jiantuan').click(function() {
                $.unblockUI();
                return false;
                });



});
